<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<script src="./classWorker.js"></script>
</head>
<body>
 
<div>计数：<span id="res"> </span></div>
<button onclick="startWorker()">开始工作</button> 
<button onclick="stopWorker()">停止工作</button>
<script>
function demo() {
    let num = 0;
    function f() {
        postMessage({num, name: '大伟聊前端'});
        num++;
        setTimeout(f, 500);
    }
    f();
}
let worker = new MyWorker(demo, function(data) {console.log(data.num)});

function startWorker () {
    worker.start();
}
function stopWorker () {
    worker.end()
}
</script>
</body>
</html>
